package bintree.leetcode;

//101. 对称二叉树

public class Num101_isSymmetric {
    public boolean isSymmetric(TreeNode root) {
        if(root==null){
            return true;
        }
        return isMirror(root.left,root.right);
    }
    private boolean isMirror(TreeNode left, TreeNode right) {
        if (left == null && right == null) {
            return true;
        }
        if (left == null || right == null) {
            return false;
        }
        if (left.val != right.val) {
            return false;
        }
        // left的左树要和right的右树镜像相等 && left的右树要和right的左树镜像相等
        return isMirror(left.left,right.right) && isMirror(left.right,right.left);
    }

}
